package com.mxpio.erp.common;

import com.mxpio.erp.common.technology.entity.ItemGroup;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @Author : 吴盼盼
 * @Datetime : 2022/11/10 14:19
 * @Desc :
 * @Modor :  Modifytime:
 * @modDesc :
 */
public class ItemGroupUtil {
    public static ItemGroup getItemGroupFromList(List<ItemGroup> list, String groupCode){
        if (list==null||list.size()==0|| StringUtils.isBlank(groupCode)){
            return null;
        }
        ItemGroup returnGroup = null;
        for (ItemGroup group:list){
            if (group.getGroupCode().equals(groupCode)){
                returnGroup = group;
                return returnGroup;
            }else{
                if (group.getChildren()!=null &&group.getChildren().size()>0){
                    returnGroup =  getItemGroupFromList(group.getChildren(),groupCode);
                    if (returnGroup!=null){
                        break;
                    }
                }
            }
        }
        return returnGroup;
    }

    //递归查询物料组及子物料组对应的groupcode
    public static void getAllGroupCodeFromItemGroup(List<String> groupCodes,ItemGroup itemGroup){
        if (itemGroup==null){
            return ;
        }
        //List<String> groupCodes = new ArrayList<>();
        groupCodes.add(itemGroup.getGroupCode());
        if (itemGroup.getChildren()!=null&&itemGroup.getChildren().size()>0){
            for (ItemGroup group:itemGroup.getChildren()){
                getAllGroupCodeFromItemGroup(groupCodes,group);
            }
        }
    }
}
